﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class QuickSort
{
    public static void Sort(int[] a, int left, int right)
    {       
        int copy = 0;
        int i = left;
        int j = right;
        int pivot = a[left];    
   
        while(i < j)
        {
            
            while(a[i] < pivot)
            {
                i++;
            }
            while(a[j] > pivot)
            {
                j--;
            }
            copy = a[i];
            a[i] = a[j];
            a[j] = copy;
            i++;
            j--;          
        }

        if (left < j)
        {
            Sort(a, left, j);
        }

        if (i < right)
        {
            Sort(a, i, right);
        }     

    }

    static void Main()
    {      
        int[] numbers = { 6, 5, 3, 1, 8, 7, 2, 4 };
        int size = numbers.Length - 1;
        int left = 0;
        int right = numbers.Length - 1;
        Sort(numbers, left, right);
        foreach (var x in numbers)
        {
            Console.WriteLine(x);
        }
    }
}